﻿using System;
using System.Xml;
using System.Text;
using System.Collections.Generic;
using InfoCenter.Agent.Helpers;
using System.Data;
using System.IO;
using System.Drawing;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
namespace SXDXClient
{ 
    public partial class frmMain : Form
    {
        public string Log
        {
            get
            {
                return txtLog.Text;
            }
            set
            {
                txtLog.Text = value;
            }
        }
        private const int WM_LED_NOTIFY = 1025;
        LEDClient LEDClient = new LEDClient();
        string result = "";
        int x = 0;
        int y = 0;
        int width = 288;
        int height = 64;
        string font = "";
        Int32 inmethod = 1;
        Int32 inspeed = 1;
        Int32 outmethod = 1;
        Int32 outspeed = 1;
        Int32 stopmethod = 0;
        Int32 stopspeed = 1;
        Int32 stoptime = 1000;
        int pwidth = 288;
        int pheight = 64;
        string IsUseLEDbyIP = "1";
        public string nLEDID
        {
            get
            {
                if (IsUseLEDbyIP == "1")
                {
                    if (IPAdd.Text.ToString().Trim() != "")
                        return IPAdd.Text.ToString().Trim();
                }
                return LEDID.Text.ToString();
            }
        }
        public int nBright
        {
            get
            {
                return System.Convert.ToInt32(txtBright.Text.ToString()); ;
            }
        }
        public string ListLED
        {
            get
            {
                return txtListLED.Text.ToString(); 
            }
        }

        public string fileBmp
        {
            get
            {
                return txtBmp.Text.ToString();
            }
        }
        public ushort SH
        {
            get
            {
                return System.Convert.ToUInt16(textSH.Text.ToString());
            }
        }
        public ushort SM
        {
            get
            {
                return System.Convert.ToUInt16(textSM.Text.ToString());
            }
        }
        public ushort TH
        {
            get
            {
                return System.Convert.ToUInt16(textTH.Text.ToString());
            }
        }
        public ushort TM
        {
            get
            {
                return System.Convert.ToUInt16(textTM.Text.ToString());
            }
        }
        string Font1
        {
            get
            {
                return nFont1.Text.ToString().Trim();    
            }
        }

        string Font2
        {
            get
            {
                return nFont2.Text.ToString().Trim();
            }
        }
        string Font3
        {
            get
            {
                return nFont3.Text.ToString().Trim();
            }
        }
        string Fontu
        {
            get
            {
                return uFont.Text.ToString().Trim();
            }
        }
        string TXT1
        {
            get
            {
                string str = nText1.Text.ToString().Trim();
                str = str.Replace("&", "&amp;");
                str = str.Replace("<", "&lt;");
                return str;
            }
        }
        string TXT21
        {
            get
            {
                string str = nText21.Text.ToString().Trim();
                str = str.Replace("&", "&amp;");
                str = str.Replace("<", "&lt;");
                return str;
            }
        }
        string TXT22
        {
            get
            {
                string str = nText22.Text.ToString().Trim();
                str = str.Replace("&", "&amp;");
                str = str.Replace("<", "&lt;");
                return str;
            }
        }
        string TXT3
        {
            get
            {
                string str = nText3.Text.ToString().Trim();
                str = str.Replace("&", "&amp;");
                str = str.Replace("<", "&lt;");
                return str; 
            }
        }
        int FontS1
        {
            get
            {
                return System.Convert.ToInt32(nFontS1.Text.ToString().Trim());
            }
        }
        int FontS2
        {
            get
            {
                return System.Convert.ToInt32(nFontS2.Text.ToString().Trim());
            }
        }
        int FontS3
        {
            get
            {
                return System.Convert.ToInt32(nFontS3.Text.ToString().Trim());
            }
        }
        int FontS
        {
            get
            {
                return System.Convert.ToInt32(uFontS.Text.ToString().Trim());
            }
        }
        
        int GetColor(string value)
        {
            int result = 0xff;
            switch (value.Trim())
            { 
                case "红色":
                    result = 0xff;
                    break;
                case "黄色":
                    result = 0xffff;
                    break;
                case "绿色":
                    result = 0xff00;
                    break;
            }
            return result;
        }
        
        public frmMain()
        {
            InitializeComponent();
        }  

        private void frmMain_Load(object sender, EventArgs e)
        {
            Logger.Debug("Start listener thread");

            //cmbDevType.SelectedIndex = 1;
            //cmbBaudRate.SelectedIndex = 0;
            int reset = 0;

            //reset = 1;
            LEDClient.LED_Startup(IsUseLEDbyIP, reset);
            //LEDSender.Do_LED_CloseDeviceOnTerminate(1);
        }

        private void frmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            LEDClient.LED_Cleanup();
        }

        private void btnPowerOn_Click(object sender, EventArgs e)
        {
            StartUpAndShowIP(nLEDID);
        }

        private void btnPowerOff_Click(object sender, EventArgs e)
        {
            result=LEDClient.SwithPower(nLEDID, 0, 0);
            Log ="SwithPower:" +result;
        }

        private void btnGetPower_Click(object sender, EventArgs e)
        {
            result = LEDClient.LED_GetPower(nLEDID);
            Log = result;
        }

        private void btnSetBright_Click(object sender, EventArgs e)
        {
            result=LEDClient.LED_SetBright(nLEDID, nBright);
            Log ="LED_SetBright:"+ result;
        }

        private void btnGetBright_Click(object sender, EventArgs e)
        {
            result = LEDClient.LED_GetBright(nLEDID);
            Log = result;
        }

        private void btnAdjustTime_Click(object sender, EventArgs e)
        {
            result = LEDClient.LED_AdjustTime(nLEDID);
            Log ="LED_AdjustTime:"+ result;
        }

        private void btnGetDisplay_Click(object sender, EventArgs e)
        {
            this.imgScreen.ImageLocation = null;
            string filepath = @"D:\SXDFile\Temp\InBoard.dat";
            if (System.IO.File.Exists(filepath))
            {
                System.IO.File.Delete(filepath);
            }
           result = LEDClient.LED_GetPlayContent(nLEDID);
           result = LEDClient.LED_GetFileContent(nLEDID);
            int times = 0;
            while (result == "-1")
            {
                Thread.Sleep(10);
                result = LEDClient.LED_GetFileContent(nLEDID);
                times++;
                if (times > 1000)
                    break;
            }
            if (result == "-1")
                return;
              
            byte[] bytes=Convert.FromBase64String(result);
            MemoryStream ms=new MemoryStream();
            FileStream file = new FileStream(filepath, FileMode.Create, System.IO.FileAccess.Write);
            ms.Read(bytes, 0, (int)ms.Length);
            file.Write(bytes, 0, bytes.Length);
            ms.Close();
            file.Close();
            result = LEDClient.LED_PreviewFile(nLEDID,nDelay.Text);
            if (result == "-1")
                return;
            string fileBmp = @"D:\SXDFile\CurrentSreen,jpg";
            byte[] ba = Convert.FromBase64String(result);
            //Image  bmp = BitmapFromByteArray(ba);
            LEDClient.SaveToFile(ba, fileBmp);
            this.imgScreen.ImageLocation = fileBmp;
            /*show.LEDSender.Do_LED_PreviewFile(256, 64, filepath);*/  
        }

        private void btnChapterEx_Click(object sender, EventArgs e)
        {
      

            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            if (result.StartsWith("EX:"))
            {
                return;
            }
            ushort K = System.Convert.ToUInt16(result);
            result = LEDClient.LED_AddChapterEx(nLEDID, K, 30000, "WAIT_CHILD", 1, 127, 2013, 1, 1, SH, SM, 0, 0, 2013, 12, 31, TH, TM, 0, 0);
            result = LEDClient.LED_AddRegion(nLEDID, K, 0, 0, 288, 32, 0);
            result = LEDClient.LED_AddLeaf(nLEDID, K, 10000, "WAIT_CHILD");
            result = LEDClient.LED_AddText(nLEDID, K, 0, 0, 288, 32, 1, 0, "开始播放", "宋体", 12, 0xff, "WFS_NONE", 1, 0, 1, 1, 1, 1, 0, 1, 3);
            result = LEDClient.LED_SendToScreen(nLEDID, K, 1);
        }

        private void btnText_Click(object sender, EventArgs e)
        {
            string text = "";
            x = 0;
            y = 0;
            width = 288;
            height = 288;

            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            if (result.StartsWith("EX:"))
            {
                return;
            }
            int K = System.Convert.ToInt32(result);

            LEDClient.LED_AddChapter(nLEDID, K, 5000, "WAIT_USE_TIME");
            LEDClient.LED_AddRegion(nLEDID, K, 0, 0, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 5000, "WAIT_USE_TIME");
            //LEDClient.LED_AddWindow(nLEDID, K, 0, 0, width, height, 1, 0, "A1.jpg", 288, 64, 0, 1, 1, 1, 1, 1, 0, 3); 
            //LEDClient.LED_AddPicture(nLEDID, K, x, y, width, height, 1, 0, "A1.jpg", 0, 1, 1, 1, 1, 1, 0, 1000);
            LEDClient.LED_AddMovie(nLEDID, K, x, y, width, height, 1, 0, "B5.gif", 0);
            LEDClient.LED_SendToScreen(nLEDID, K, 1);
        }
        private void Test2()
        {
            string text = "";
            int K = 0;
            Log = "Start data";
            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            if (result.StartsWith("EX:"))
            {
                return;
            }
            K = System.Convert.ToInt32(result);
            x = 0; y = 0; width = 288; height = 32;
            uint time = 1000;
            LEDClient.LED_AddChapter(nLEDID, K, 20 * time, "WAIT_CHILD");
            x = 0; y = 16; width = 288; height = 16;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 20 * time, "WAIT_CHILD");
            LEDClient.LED_AddText(nLEDID, K, x, y, width, height, 1, 0, "时间", "宋体", 12, 0xff, "WFS_NONE", 1, 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);
            /*
            x = 0; y = 48; width = 288; height = 16;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 5 * time, "WAIT_CHILD");
            inmethod = 2;
            inspeed = 4;
            LEDClient.LED_AddText(nLEDID, K, x, y, width, height, 1, 0, "杭州地铁二号线欢迎您", "宋体", 12, 0xffff, "WFS_NONE", 1, 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);
            LEDClient.LED_AddLeaf(nLEDID, K, 5 * time, "WAIT_CHILD");
            LEDClient.LED_AddText(nLEDID, K, x, y, width, height, 1, 0, "武林广场站E出入口", "宋体", 12, 0xff00, "WFS_NONE", 1, 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);

            inmethod = 4; inspeed = 5;
            LEDClient.LED_AddLeaf(nLEDID, K, 5 * time, "WAIT_CHILD");
            text = LEDClient.LED_GetText(23);
            LEDClient.LED_AddText(nLEDID, K, x, y, width, height, 1, 0, text, "宋体", 12, 0xff00, "WFS_NONE", 1, 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);
            */
            result = LEDClient.LED_SendToScreen(nLEDID, K, 1);
            Log = result;

        }
        private void Test1()
        { 
            string text = "";
            int K = 0;
            Log = "Start data";
            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_DOWNLOAD", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            if (result.StartsWith("EX:"))
            {
                return;
            }
            K = System.Convert.ToInt32(result);
            x = 0; y = 0; width = 288; height = 16;
            uint time = 1000;
            LEDClient.LED_AddChapter(nLEDID, K, 20 * time, "WAIT_CHILD");
            x = 0; y = 0; width = 288; height = 16;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 20 * time, "WAIT_CHILD");
            LEDClient.LED_AddDateTimeEx(nLEDID, K, x, y, width, height, 1, 0, 0,Font1, FontS1, GetColor(txtFNC1.Text), "WFS_NONE", 0, 0, 0, 0, TXT1);

            x = 0; y = 16; width = 288; height = 32;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 10 * time, "WAIT_CHILD"); 
            inmethod = 1;
            inspeed = 1;
            LEDClient.LED_AddTextB(nLEDID, K, 0, 0, width, height, 1, 0, TXT21, Font2, FontS2, GetColor(txtFNC2.Text), "WFS_NONE", 1, 1, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);
            LEDClient.LED_AddLeaf(nLEDID, K, 10 * time, "WAIT_CHILD");
            inmethod = 1; inspeed = 1;
            LEDClient.LED_AddText(nLEDID, K, 0, 0, width, height, 1, 0, TXT22, Font2, FontS2, GetColor(txtFNC2.Text), "WFS_NONE", 1, 1, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);

            x = 0; y = 48; width = 288; height = 16;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 10 * time, "WAIT_CHILD");
           
            inmethod = 2;
            inspeed = 1;
            LEDClient.LED_AddText(nLEDID, K, 0, 0, width, height, 1, 0, TXT3, Font3, FontS3, GetColor(txtFNC3.Text), "WFS_NONE", 1, 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);

            Log = "Start Sending data";
            result = LEDClient.LED_SendToScreen(nLEDID, K, 1);
            Log = result;
        }
        private void btnTextNoStruct_Click(object sender, EventArgs e)
        {
            Test1(); 
        }

        private void btnDib_Click(object sender, EventArgs e)
        {


            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            if (result.StartsWith("EX:"))
            {
                return;
            }
            int num = System.Convert.ToInt32(result);
            LEDClient.LED_AddChapter(nLEDID, num, 30000, "WAIT_CHILD");
            LEDClient.LED_AddRegion(nLEDID, num, 0, 0, 128, 32, 0);

            LEDClient.LED_AddLeaf(nLEDID, num, 10000, "WAIT_CHILD");
            LEDClient.LED_AddWindow(nLEDID, num, 0, 0, 128, 32, 1, 0, "A1.jpg", 128, 32, 0, 1, 1, 1, 1, 1, 0, 3000);
            LEDClient.LED_SendToScreen(nLEDID, num, 1);
        }

        private void btnPicFile_Click(object sender, EventArgs e)
        {
            string text = "";
            x = 0;
            y = 0;
            width = 288;
            height = 288;

            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            if (result.StartsWith("EX:"))
            {
                return;
            }
            int K = System.Convert.ToInt32(result);

            result=LEDClient.LED_AddChapter(nLEDID, K, 5000, "WAIT_USE_TIME");
            result=LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            result=LEDClient.LED_AddLeaf(nLEDID, K, 5000, "WAIT_USE_TIME");
            result=LEDClient.LED_AddPicture(nLEDID, K, 0, 0, width, height, 1, 0, "A10.jpg", 0, 1, 1, 1, 1, 1, 0, 1000);
            result=LEDClient.LED_SendToScreen(nLEDID, K, 1);
            Log = "LED_SendToScreen:" + result;
        }

        private void btnString_Click(object sender, EventArgs e)
        {
            result = LEDClient.LED_GetTypeOfContent(nLEDID);
            Log = result;
        }

        private void btnDateTime_Click(object sender, EventArgs e)
        {
            string text = "";
            int K = 0;
            Log = "Start data";
            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            if (result.StartsWith("EX:"))
            {
                return;
            }
            K = System.Convert.ToInt32(result);
            x = 0; y = 0; width = 128; height = 32;
            uint time = 1000;
            font = LEDClient.LED_GetFont(1);
            LEDClient.LED_AddChapter(nLEDID, K, 20 * time, "WAIT_CHILD");
            x = 0; y = 16; width = 80; height = 32;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 2 * time, "WAIT_CHILD");
            LEDClient.LED_AddDateTimeEx(nLEDID, K, x, y, width, height, 1, 0, 0, font, 12, 0xffff, "WFS_NONE", 0, 0, 0, 0, "#y-#m-#d");
            /*
            x = 40; y = 20; width = 80; height = 32;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddDateTimeEx(nLEDID, K, x, y, width, height, 1, 0, 1, font, 12, 0xff, "WFS_NONE", 0, 0, 0, 0, "#y-#m-#d");
           */
            x = 0; y = 0; width = 288; height = 32;      //第1页面
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 5 * time, "WAIT_CHILD");
            LEDClient.LED_AddClockEx2(nLEDID, K, x, y, width, height, 1, 0, 0, 0, 0x0, 0xfff, 1, "SHAPE_ROUNDRECT", 30, 3, 0xff00, 2, 0xffff, 0, 1, 0xff, 3, 0xffff, 2, 0xff00, 1, 0xff);
            LEDClient.LED_SendToScreen(nLEDID, K, 1);
        }

        private void btnCountUp_Click(object sender, EventArgs e)
        {
            result = LEDClient.LED_SavePicture(fileBmp);
            Log = result;
        }
        private void btnClock_Click(object sender, EventArgs e)
        {


        }
        private void btnCountDown_Click(object sender, EventArgs e)
        {

            ushort K;
            TTimeStamp basetime = new TTimeStamp();
            TSystemTime T = new TSystemTime();
            DateTime dtNow = System.DateTime.Now;

            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            int num = System.Convert.ToInt32(result);
            LEDClient.LED_AddChapter(nLEDID, num, 30000, "WAIT_CHILD");
            LEDClient.LED_AddRegion(nLEDID, num, 0, 0, 128, 32, 0);



            LEDClient.LED_AddLeaf(nLEDID, num, 10000, "WAIT_CHILD");


            LEDClient.EncodeDateTime(ref T, (ushort)dtNow.Year, (ushort)dtNow.Month, (ushort)dtNow.Day, 1, 0, 0, 0);
            LEDClient.SystemTimeToTimeStamp(ref T, ref basetime);

            LEDClient.LED_AddCounter(nLEDID, num, 0, 0, 128, 32, 1, 0, "CT_COUNTDOWN", "CF_HNS", "Times New Roman", 12, 0xff, "WFS_NONE", basetime.time, basetime.date);

            LEDClient.EncodeDateTime(ref T, 1899, 1, 1, 1, 29, 0, 0);
            LEDClient.SystemTimeToTimeStamp(ref T, ref basetime);
            LEDClient.LED_AddCounter(nLEDID, num, 0, 10, 128, 32, 1, 0, "CT_COUNTDOWN", "CF_HNS", "Times New Roman", 12, 0xff, "WFS_NONE", basetime.time, basetime.date);
            LEDClient.LED_SendToScreen(nLEDID, num, 1);
        }

        private void btnCampaign_Click(object sender, EventArgs e)
        {
             
        } 

        private void btnChapter_Click(object sender, EventArgs e)
        {
            ushort K;
            /*
            K = (ushort)LEDSender.Do_MakeChapter(LEDSender.ROOT_PLAY_CHAPTER, LEDSender.ACTMODE_REPLACE, 0, LEDSender.COLOR_MODE_DOUBLE, 5000, LEDSender.WAIT_CHILD);
            LEDSender.Do_AddRegion(K, 0, 0, 128, 32, 0);
            LEDSender.Do_AddLeaf(K, 10000, LEDSender.WAIT_CHILD);
            LEDSender.Do_AddText(K, 0, 0, 64, 16, LEDSender.V_TRUE, 0, "Hello world! HELLO WORLD!", "宋体", 12, 0xff, LEDSender.WFS_NONE, LEDSender.V_TRUE, 0, 0, 1, 1, 1, 0, 1, 3);

            Parse(LEDSender.Do_LED_SendToScreen(ref param, K));
            */
        }

        private void btnRegion_Click(object sender, EventArgs e)
        {
            /*
            
            ushort K; 
         
            K = (ushort)LEDSender.Do_MakeRegion(LEDSender.ROOT_PLAY_REGION, LEDSender.ACTMODE_REPLACE, 0, 0, LEDSender.COLOR_MODE_DOUBLE, 0, 0, 128, 32, 0);
            LEDSender.Do_AddLeaf(K, 10000, LEDSender.WAIT_CHILD);
            LEDSender.Do_AddText(K, 0, 0, 64, 16, LEDSender.V_TRUE, 0, "Hello world! HELLO WORLD!", "宋体", 12, 0xff, LEDSender.WFS_NONE, LEDSender.V_TRUE, 0, 0, 1, 1, 1, 0, 1, 3);

            Parse(LEDSender.Do_LED_SendToScreen(ref param, K));
            */
        }

        private void btnLeaf_Click(object sender, EventArgs e)
        {
            ushort K;
            uint time = System.Convert.ToUInt32(txtTime.Text);
            result = LEDClient.LED_MakeLeaf(nLEDID, "ROOT_PLAY_LEAF", "ACTMODE_REPLACE", 0, 2, 0, "COLOR_MODE_DOUBLE", time, "WAIT_CHILD");
            K = System.Convert.ToUInt16(result);
            inmethod = System.Convert.ToInt32(txtMethod.Text);
            inspeed = System.Convert.ToInt32(txtSpeed.Text);
            string str = txtNormal.Text.ToString().Trim();
            str = str.Replace("&", "&amp;");
            str = str.Replace("<", "&lt;");

            LEDClient.LED_AddText(nLEDID, K, 0, 0, 288, 16, 1, 0, str, Font3, FontS3, GetColor(txtFNC3.Text), "WFS_NONE", 0, 0, inmethod, inspeed, 1, 0, 0, 0, 1000);
            Text = "开始发送数据";
            result = LEDClient.LED_SendToScreen(nLEDID, K, 0);
            Text = result;

        }
        private void btnObject_Click(object sender, EventArgs e)
        {
            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS", "3");
            if (result.StartsWith("EX:"))
            {
                return;
            }
            int K = System.Convert.ToInt32(result);
            LEDClient.LED_AddChapter(nLEDID, K, 5000, "WAIT_CHILD");
            LEDClient.LED_AddRegion(nLEDID, K, 0, 0, 288, 64, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 5000, "WAIT_CHILD");
            string str = nTXT31.Text.ToString().Trim();
            str = str.Replace("&", "&amp;");
            str = str.Replace("<", "&lt;");
            LEDClient.LED_AddText(nLEDID, K, 0, 0, 288, 64, 1, 0, str, Fontu, FontS, GetColor(txtFUC.Text), "WFS_NONE", 0, 0, 2, 1, 1, 0, 1, 0, 1000);
            LEDClient.LED_SendToScreen(nLEDID, K, 1); 
        }
        private void btnOnlineServerStartup_Click(object sender, EventArgs e)
        {

        }

        private void btnOnlineServerCleanup_Click(object sender, EventArgs e)
        {
            //LEDSender.Do_LED_Report_RemoveServer(0);

        }

        private void btnOnlineGetList_Click(object sender, EventArgs e)
        {
            result =LEDClient.LED_GetLEDList();
            Log = result;
        } 

        UInt32 serialno = 0;

        private void timerMain_Tick(object sender, EventArgs e)
        {

            ushort I, K;
            string text;

            for (I = 1; I <= 4; I++)
            {
                
                /*
                result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
                int num = System.Convert.ToInt32(result);
                LEDClient.LED_AddChapter(nLEDID, num, 30000, "WAIT_CHILD");
                LEDClient.LED_AddRegion(nLEDID, num, 0, 0, 128, 32, 0);
                //第1页面
                LEDClient.LED_AddLeaf(nLEDID, num, 10000, "WAIT_CHILD");
                text = "IP=" + I + "\r\n" + "序列号=" + serialno;
                LEDClient.LED_AddText(nLEDID, num,0, 0, 128, 32, LEDSender.V_TRUE, 0, text, "宋体", 12, 0xff, "WFS_NONE", 1, 0, 1, 5, 1, 1, 0, 1, 3000);
                serialno++;                
                Text = "<" + param.devParam.rmtHost + ">正在发送数据...";
                LEDClient.LED_SendToScreen(nLEDID, num); 
                */
            }
        }



        private void btnBoardParam_Click(object sender, EventArgs e)
        {

            result = LEDClient.LED_Registration(LEDID.Text.ToString(), "  ", "LED04", IPAdd.Text.ToString().Trim(), "01-01-F1-DE-1A-02", "DEVICE_TYPE_UDP", "SBR_57600", "8889", "0", "SCREEN_COLOR", "6666", "1", "288", "64");
            Log = "LEDClient.LED_Registration"+result;
            /*LEDClient.LED_Registration("2", "  ", "LED04", "192.168.0.101", "01-01-F1-DE-1A-02", "DEVICE_TYPE_UDP", "SBR_57600", "8889", "0", "SCREEN_COLOR", "6666", "1", "288", "64");
            Log = "LEDClient.LED_Registration" + result;
            LEDClient.LED_Registration("3", "  ", "LED04", "10.0.10.83", "01-01-F1-DE-1A-02", "DEVICE_TYPE_UDP", "SBR_57600", "8889", "0", "SCREEN_COLOR", "6666", "1", "288", "64");
            Log = "LEDClient.LED_Registration" + result;
            LEDClient.LED_Registration("4", "  ", "LED04", "10.0.10.80", "01-01-F1-DE-1A-02", "DEVICE_TYPE_UDP", "SBR_57600", "8889", "0", "SCREEN_COLOR", "6666", "1", "288", "64");
            Log = "LEDClient.LED_Registration" + result;*/
            //SCREEN_UNICOLOR:   单色显示屏
            //SCREEN_COLOR:       双色显示屏
            //SCREEN_FULLCOLOR:  全彩色256级灰度显示屏
            //SCREEN_GRAY:         双基色256级灰度显示屏
        }
        public void StartUpAndShowIP(string nLEDID)
        {
            string ip = LEDClient.SwithPower(nLEDID, 1, 1);
            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_DOWNLOAD", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            if (result.StartsWith("EX:"))
            {
                return;
            }
            ushort K = System.Convert.ToUInt16(result);
            LEDClient.LED_AddChapter(nLEDID, K, 30000, "WAIT_CHILD");
            LEDClient.LED_AddRegion(nLEDID, K, 0, 0, 128, 32, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 10000, "WAIT_CHILD");
            LEDClient.LED_AddText(nLEDID, K, 0, 0, 128, 64, 1, 0, ip, "宋体", 12,0xFF00, "WFS_NONE", 1, 0, 0, 1, 1, 1, 0, 1, 3);
            LEDClient.LED_SendToScreen(nLEDID, K, 1);
        }
        private void btnMultiCard_Click(object sender, EventArgs e)
        {/*
            TSenderParam param = new TSenderParam();
            ushort K;
            int x, y, cx, cy;

            GetDeviceParam(ref param.devParam);
            param.notifyMode = LEDSender.NOTIFY_BLOCK;
            param.wmHandle = (UInt32)Handle;
            param.wmMessage = WM_LED_NOTIFY;

            x = 0;
            y = 0;
            cx = 320;
            cy = 176;

            //----------------------------

            K = (ushort)LEDSender.Do_MakeRoot(LEDSender.ROOT_PLAY, LEDSender.COLOR_MODE_DOUBLE, LEDSender.SURVIVE_ALWAYS);

            LEDSender.Do_AddChapter(K, 1000, LEDSender.WAIT_USE_TIME);
            LEDSender.Do_AddRegion(K, x, y, cx, cy, 0);
            LEDSender.Do_AddLeaf(K, 1000, LEDSender.WAIT_CHILD);
            LEDSender.Do_AddText(K, x, y, cx, cy, LEDSender.V_TRUE, 0, "行人通过马路时，请注意安全。珍惜生命，严禁酒后驾车。开车时请您系好安全带。", "宋体", 24, 0xff, LEDSender.WFS_NONE, LEDSender.V_TRUE, 0, 1, 1, 1, 1, 0, 1, 3);

            LEDSender.Do_AddChapter(K, 1000, LEDSender.WAIT_USE_TIME);
            LEDSender.Do_AddRegion(K, x, y, cx, cy, 0);
            LEDSender.Do_AddLeaf(K, 1000, LEDSender.WAIT_CHILD);
            LEDSender.Do_AddText(K, x, y, cx, cy, LEDSender.V_TRUE, 0, "行人通过马路时，请注意安全。珍惜生命，严禁酒后驾车。开车时请您系好安全带。", "宋体", 24, 0xff00, LEDSender.WFS_NONE, LEDSender.V_TRUE, 0, 1, 1, 1, 1, 0, 1, 3);

            Text = "正在发送1...";
            param.devParam.rmtHost = "43.35.162.36";
            Parse2(LEDSender.Do_LED_SendToScreen(ref param, K));

            //----------------------------

            K = (ushort)LEDSender.Do_MakeRoot(LEDSender.ROOT_PLAY, LEDSender.COLOR_MODE_DOUBLE, LEDSender.SURVIVE_ALWAYS);

            LEDSender.Do_AddChapter(K, 1000, LEDSender.WAIT_USE_TIME);
            LEDSender.Do_AddRegion(K, x, y, cx, cy, 0);
            LEDSender.Do_AddLeaf(K, 1000, LEDSender.WAIT_CHILD);
            LEDSender.Do_AddText(K, x, y, cx, cy, LEDSender.V_TRUE, 0, "行人通过马路时，请注意安全。珍惜生命，严禁酒后驾车。开车时请您系好安全带。", "宋体", 24, 0xff, LEDSender.WFS_NONE, LEDSender.V_TRUE, 0, 1, 1, 1, 1, 0, 1, 3);

            LEDSender.Do_AddChapter(K, 1000, LEDSender.WAIT_USE_TIME);
            LEDSender.Do_AddRegion(K, x, y, cx, cy, 0);
            LEDSender.Do_AddLeaf(K, 1000, LEDSender.WAIT_CHILD);
            LEDSender.Do_AddText(K, x, y, cx, cy, LEDSender.V_TRUE, 0, "行人通过马路时，请注意安全。珍惜生命，严禁酒后驾车。开车时请您系好安全带。", "宋体", 24, 0xff00, LEDSender.WFS_NONE, LEDSender.V_TRUE, 0, 1, 1, 1, 1, 0, 1, 3);

            Text = "正在发送2...";
            param.devParam.rmtHost = "43.35.162.37";
            Parse2(LEDSender.Do_LED_SendToScreen(ref param, K));

            //----------------------------

            K = (ushort)LEDSender.Do_MakeRoot(LEDSender.ROOT_PLAY, LEDSender.COLOR_MODE_DOUBLE, LEDSender.SURVIVE_ALWAYS);

            LEDSender.Do_AddChapter(K, 1000, LEDSender.WAIT_USE_TIME);
            LEDSender.Do_AddRegion(K, x, y, cx, cy, 0);
            LEDSender.Do_AddLeaf(K, 1000, LEDSender.WAIT_CHILD);
            LEDSender.Do_AddText(K, x, y, cx, cy, LEDSender.V_TRUE, 0, "行人通过马路时，请注意安全。珍惜生命，严禁酒后驾车。开车时请您系好安全带。", "宋体", 24, 0xff, LEDSender.WFS_NONE, LEDSender.V_TRUE, 0, 1, 1, 1, 1, 0, 1, 3);

            LEDSender.Do_AddChapter(K, 1000, LEDSender.WAIT_USE_TIME);
            LEDSender.Do_AddRegion(K, x, y, cx, cy, 0);
            LEDSender.Do_AddLeaf(K, 1000, LEDSender.WAIT_CHILD);
            LEDSender.Do_AddText(K, x, y, cx, cy, LEDSender.V_TRUE, 0, "行人通过马路时，请注意安全。珍惜生命，严禁酒后驾车。开车时请您系好安全带。", "宋体", 24, 0xff00, LEDSender.WFS_NONE, LEDSender.V_TRUE, 0, 1, 1, 1, 1, 0, 1, 3);

            Text = "正在发送3...";
            param.devParam.rmtHost = "43.35.162.35";
            Parse2(LEDSender.Do_LED_SendToScreen(ref param, K));
            */
        }

        private void button1_Click(object sender, System.EventArgs e)
        { 
            result=LEDClient.SwithPower(nLEDID, 1, 0);
            Log = "SwithPower(nLEDID, 1, 0):"+result;
        }

        private void button2_Click(object sender, System.EventArgs e)
        {
            char[] delimiterChars = { ';', ',', '.', ':', '\t' };

            string IPs = ListLED;
            System.Console.WriteLine("Original text: '{0}'", IPs);

            string[] led = IPs.Split(delimiterChars);
            foreach (string ip in led)
            {
                LEDClient.SwithPower(ip, 0, 0);
            }
            Log = IPs + " 关闭";
            foreach (string ip in led)
            {
                LEDClient.SwithPower(ip, 1, 0);
            }
            Log = IPs + " 打开";
        }

        private void button4_Click(object sender, System.EventArgs e)
        {
            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS","1");
            if (result.StartsWith("EX:"))
            {
                return;
            }
            int K = System.Convert.ToInt32(result);
            LEDClient.LED_AddChapter(nLEDID, K, 5000, "WAIT_CHILD");
            LEDClient.LED_AddRegion(nLEDID, K, 0, 0, 288, 64, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 5000, "WAIT_CHILD");
            string str = nTXT11.Text.ToString().Trim();
            str = str.Replace("&", "&amp;");
            str = str.Replace("<", "&lt;");
            LEDClient.LED_AddText(nLEDID, K, 0, 0, 288, 64, 1, 0, str, Fontu, FontS, GetColor(txtFUC.Text), "WFS_NONE", 0, 0, 2, 5, 1, 0, 1, 0, 1);
            LEDClient.LED_SendToScreen(nLEDID, K, 1); 
        }

        private void button5_Click(object sender, System.EventArgs e)
        {
            result=LEDClient.LED_ResetDisplay(nLEDID);
            Log = "LED_ResetDisplay:" + result;
        }

        private void groupBox3_Enter(object sender, System.EventArgs e)
        {

        }

        private void label4_Click(object sender, System.EventArgs e)
        {

        } 
 
        private void button7_Click(object sender, System.EventArgs e)
        {
            LEDClient.LED_Cleanup();
        }

        private void cmbMethod_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            txtMethod.Text= (cmbMethod.SelectedIndex).ToString();
        }

        private void button6_Click(object sender, System.EventArgs e)
        {

        }

    }
}
